import { Router, Route, IndexRoute, hashHistory } from 'react-router';
import Refast, { LogicRender } from 'refast';
import { Component } from 'react';
import { render } from 'react-dom';
import FastClick from 'fastclick';
import { Toast, Dialog } from 'saltui';

import { isDev } from 'variables';
//引入页面，配置下方的路由nom
import PageHome from 'pages/questionnaire/home';
import Add from 'pages/questionnaire/add';
import Edit from 'pages/questionnaire/edit';
import View from 'pages/questionnaire/view';
import MyQues from 'pages/questionnaire/my_ques';
import Info from 'pages/questionnaire/ques_info';
import examView from 'pages/questionnaire/exam_view';
import Design from 'pages/questionnaire/design';
import BackReason from 'pages/questionnaire/back_reason';
import Statis from 'pages/questionnaire/statistics/list';
import StatisDetail from 'pages/questionnaire/statistics/detail';
import StatisResult from 'pages/questionnaire/statistics/result';
import DetailInfo from 'pages/questionnaire/statistics/info';
import Ranking from 'pages/questionnaire/statistics/ranking';

// import ReportInfo from 'pages/questionnaire/report_info';
// import SendUnit from 'pages/send_unit';
//
// import HelpIndex from 'pages/help/list';
// import HelpAttachment from 'pages/help/attachment';
// import HelpShenpi from 'pages/help/shenpi';
// import HelpShouwen from 'pages/help/shouwen';
// import HelpAdd from 'pages/help/add';
// import HelpAdministrator from 'pages/help/administrator';
//
// import AboutIndex from 'pages/about';
// import AboutItem1 from 'pages/about/about1';
// import AboutItem2 from 'pages/about/about2';
// import AboutItem3 from 'pages/about/about3';
// import AboutItem4 from 'pages/about/about4';
// import AboutItem5 from 'pages/about/about5';
import DB from 'db';
import './app.less';

const customHistory = hashHistory;

if (isDev && window.chrome && window.chrome.webstore) { // This is a Chrome only hack
                                                        // see https://github.com/livereload/livereload-extensions/issues/26
  setInterval(() => {
    document.body.focus();
  }, 200);
}

// bind fastclick
FastClick.attach(document.body);

// 这里使用 use 来配置 Refast
// Refast 文档 https://recore.github.io/refast-docs/
Refast.use('fn', {
  toast: Toast,
  dialog: Dialog,
  DB,
  history: customHistory,
});

const Loading = () => <div className="kuma-loading" />;
const Empty = () => <div>暂无数据</div>;

// 修改 LogicRender 增加默认配置
// 用来自定义Loading和Empty的样式
LogicRender.defaultProps.Empty = Empty;
LogicRender.defaultProps.Loading = Loading;

class App extends Component {
  render() {
    return (
      <div>
        {this.props.children}
      </div>
    );
  }
}

// login(function (result) {
//   alert(JSON.stringify(result));
//   var result = JSON.parse(result);
//   if (result.loginResult) {
//     dd.ready(function(){
//       dd.ui.webViewBounce.disable();
//     });
//     $("#userHiddenId").val(result.ezplatformUserId);
//     $("#userHiddenDDId").val(result.userId);
//     $("#token").val(result.token);
//     // if(result.dingdingType == "corp"){
//     //   realCorpId = "0";
//     // }
//     $('#baseContext').val(result.baseContext);
//     initRoute();
//     jsready(function(){});
//   } else {
//     var message = '登录失败';
//     if(result.errorMsg){
//       message = result.errorMsg;
//     }
//     alert(message);
//   }
// },function(){
//   initRoute();
// });

// function initRoute () {
// //路由配置
//   return render(
//     <Router history={customHistory}>
//       <Route name="app" path="/" component={App}>
//         <IndexRoute component={PageHome}/>
//         <Route path="questionnaire/home" component={PageHome}/>
//        <Route path="questionnaire/add" component={Add}/>
//   {/*       <Route path="questionnaire/info/:dataId/:status" component={Info}/>
//         <Route path="questionnaire/my_ques" component={MyQues}/>
//         <Route path="questionnaire/help_index" component={HelpIndex}/>
//         <Route path="questionnaire/help_attachment" component={HelpAttachment}/>
//         <Route path="questionnaire/help_shenpi" component={HelpShenpi}/>
//         <Route path="questionnaire/help_shouwen" component={HelpShouwen}/>
//         <Route path="questionnaire/Help_add" component={HelpAdd}/>
//         <Route path="questionnaire/help_administrator" component={HelpAdministrator}/>
//         <Route path="questionnaire/about_index" component={AboutIndex}/>
//         <Route path="questionnaire/about1" component={AboutItem1}/>
//         <Route path="questionnaire/about2" component={AboutItem2}/>
//         <Route path="questionnaire/about3" component={AboutItem3}/>
//         <Route path="questionnaire/about4" component={AboutItem4}/>
//         <Route path="questionnaire/about5" component={AboutItem5}/>*/}
//       </Route>
//     </Router>,
//     document.getElementById('App'),
//   );
// }
render(
  <Router history={customHistory}>
    <Route name="app" path="/" component={App}>
      <IndexRoute component={PageHome}/>
      <Route path="questionnaire/home(/:userId)" component={PageHome}/>
      <Route path="questionnaire/add" component={Add}/>
      <Route path="questionnaire/edit/:id" component={Edit}/>
      <Route path="questionnaire/view/:id" component={View}/>
      <Route path="questionnaire/my_ques(/:userId)" component={MyQues}/>
      <Route path="questionnaire/exam_view/:id(/:canToAnswer)(/:userId)" component={examView}/>
      <Route path="questionnaire/back_reason/:quesId/:id/(:type)" component={BackReason}/>
      <Route path="questionnaire/ques_info/:dataId/:status(/:canToAnswer)(/:anwser)(/:anUserId)" component={Info}/>
      <Route path="questionnaire/design/:dataId" component={Design}/>
      <Route path="questionnaire/statis(/:userId)" component={Statis}/>
      <Route path="questionnaire/statisDetail/:id(/:type)" component={StatisDetail}/>
      <Route path="questionnaire/statisResult/:id(/:type)" component={StatisResult}/>
      <Route path="questionnaire/ranking/:id" component={Ranking}/>

      <Route path="questionnaire/detailInfo/:quesId/:topicId/:topicType(/:quesType)" component={DetailInfo}/>

      {/*
        <Route path="questionnaire/help_index" component={HelpIndex}/>
        <Route path="questionnaire/help_attachment" component={HelpAttachment}/>
        <Route path="questionnaire/help_shenpi" component={HelpShenpi}/>
        <Route path="questionnaire/help_shouwen" component={HelpShouwen}/>
        <Route path="questionnaire/Help_add" component={HelpAdd}/>
        <Route path="questionnaire/help_administrator" component={HelpAdministrator}/>
        <Route path="questionnaire/about_index" component={AboutIndex}/>
        <Route path="questionnaire/about1" component={AboutItem1}/>
        <Route path="questionnaire/about2" component={AboutItem2}/>
        <Route path="questionnaire/about3" component={AboutItem3}/>
        <Route path="questionnaire/about4" component={AboutItem4}/>
        <Route path="questionnaire/about5" component={AboutItem5}/>*/}
    </Route>
  </Router>,
  document.getElementById('App'),
);
